package com.as.manager;

import java.util.List;

import com.as.dao.QuestionListDao;
import com.as.entity.QuestionList;
import com.as.tools.ArcTools;

public class QuestionListManagerImpl implements QuestionListManager{
	private QuestionListDao questionListDao;
	private ArcTools arcTools;
	public void setQuestionListDao(QuestionListDao questionListDao) {
		this.questionListDao = questionListDao;
	}
	public void setArcTools(ArcTools arcTools) {
		this.arcTools = arcTools;
	}
	@Override
	public QuestionList getQuestionList(String questionListId) {
		return questionListDao.getById(questionListId);
	}
	@Override
	public boolean addQuestionList(QuestionList questionList) {
		try{
			questionListDao.save(questionList);
			return true;
		}catch(Exception e){
			e.printStackTrace();
			return false;
		}
	}
	@Override
	public boolean deleteQuestionList(String questionListId) {
		try{
			questionListDao.delete(questionListId);
			return true;
		}catch(Exception e){
			e.printStackTrace();
			return false;
		}
	}
	@Override
	public boolean updateQuestionList(QuestionList questionList) {
		try{
			questionListDao.update(questionList);
			return true;
		}catch(Exception e){
			e.printStackTrace();
			return false;
		}
	}
	@Override
	public QuestionList createQuestionList(List<String> ids) {
		if(ids.size() == 20){
			QuestionList questionList = new QuestionList();
			questionList.setQlid(arcTools.createId());
			questionList.setQid1(ids.get(0));
			questionList.setQid2(ids.get(1));
			questionList.setQid3(ids.get(2));
			questionList.setQid4(ids.get(3));
			questionList.setQid5(ids.get(4));
			questionList.setQid6(ids.get(5));
			questionList.setQid7(ids.get(6));
			questionList.setQid8(ids.get(7));
			questionList.setQid9(ids.get(8));
			questionList.setQid10(ids.get(9));
			questionList.setQid11(ids.get(10));
			questionList.setQid12(ids.get(11));
			questionList.setQid13(ids.get(12));
			questionList.setQid14(ids.get(13));
			questionList.setQid15(ids.get(14));
			questionList.setQid16(ids.get(15));
			questionList.setQid17(ids.get(16));
			questionList.setQid18(ids.get(17));
			questionList.setQid19(ids.get(18));
			questionList.setQid20(ids.get(19));
			return questionList;
		}else{
			return null;
		}
	}
}
